08. Exercise: Implementing Log to Cart Event
Task Description:
Use the example we just completed together as a guide to determine where and how to log sendAddToCartEvent in the PastPurchasesViewController.
Task Feedback:
Great job!
Solution: [L03.02-Solution-LogAddToCartEvent][Diff]
Here is how we implemented the function:
public static void logEventAddToCart(Context context, Plant plant, long quantity) {
Bundle params = new Bundle();
params.putInt(FirebaseAnalytics.Param.ITEM_ID, plant.id);
params.putString(FirebaseAnalytics.Param.ITEM_NAME, plant.name);
params.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "plants");
params.putDouble(FirebaseAnalytics.Param.QUANTITY, quantity);
params.putDouble(FirebaseAnalytics.Param.PRICE, plant.price);
FirebaseAnalytics.getInstance(context).logEvent(
FirebaseAnalytics.Event.ADD_TO_CART, params);
}
We called the method in the onClick method for the FloatingActionButton in the PlantDetailActivity class.